<?php

defined('_SECURITY_TOKEN') or die("caia fora");

class modeluser extends model
{
	
	function __construct(  )
	{
		
		
		
	}
	
	public function save( $args=array() ){
		
		$result		=	0;
		$table_user	=	configuration::$table_user;
		
		$result		=	$this->bind( $table_user, $args );
		
		$result[]	=	(object) array( 'Field'=>'datecreate', 'Type'=>'other', 'Value'=>'now()' );
		
		$result	=	parent::save( $table_user, $result );
						
		return $result;
	}	
	
	
	public function authentication( $email, $password ){
		
		$result		=	0;
		$filter		=	array();
		$table_user	=	configuration::$table_user;
		
		$filter[]	=	'email="'.$email.'"';
		$filter[]	=	'password="'.$password.'"';
		
		$result		=	$this->getItem( $table_user, $filter, "LIMIT 0,1" );
		
		
		if( $result[0]->email == $email 
			&& $result[0]->password == $password ){
				
				$_SESSION['username']	=	$result[0]->name.' '.$result[0]->lastname;
				$_SESSION['user_id']	=	$result[0]->id;
				
				$result =	1;
			}else{
				$result	=	2;
			}
		
		//$result[]	=	(object) array( 'Field'=>'datecreate', 'Type'=>'other', 'Value'=>'now()' );
		
						
		return $result;
	}
	
}